<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="WTTWi2XnJ5">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Josefin Sans:300,300italic,400,400italic,700,700italic|Lobster:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lclong.top","root":"/","scheme":"Gemini","version":"7.7.1","exturl":true,"sidebar":{"position":"left","display":"post","padding":20,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Docker官方指引 项目Git仓库 一、项目基本情况Spring Boot项目特别简单，使用Jpa连接数据库，有一个实体类和crud四个rest接口，数据库使用MySQL5.7.34，数据库连接池使用默认的hikari。 docker-compose 需要启动的应用：Spring Boot项目， MySQL 项目结构：   application.yml: 12345678spring:  da">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Docker Compose部署Spring Boot + Mysql项目">
<meta property="og:url" content="https://lclong.top/2021/05/13/docker/docker-compose/index.html">
<meta property="og:site_name" content="Zlatanlong&#39;s T-blog">
<meta property="og:description" content="Docker官方指引 项目Git仓库 一、项目基本情况Spring Boot项目特别简单，使用Jpa连接数据库，有一个实体类和crud四个rest接口，数据库使用MySQL5.7.34，数据库连接池使用默认的hikari。 docker-compose 需要启动的应用：Spring Boot项目， MySQL 项目结构：   application.yml: 12345678spring:  da">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lclong.top/2021/05/13/docker/docker-compose/image-20210513155311383.png">
<meta property="og:image" content="https://lclong.top/2021/05/13/docker/docker-compose/image-20210513162741992.png">
<meta property="og:image" content="https://lclong.top/2021/05/13/docker/docker-compose/image-20210513170908945.png">
<meta property="og:image" content="https://lclong.top/2021/05/13/docker/docker-compose/%E6%9C%AA%E5%91%BD%E5%90%8D%E7%BB%98%E5%9B%BE.svg">
<meta property="og:image" content="https://lclong.top/2021/05/13/docker/docker-compose/image-20210513170501278.png">
<meta property="article:published_time" content="2021-05-13T09:49:35.000Z">
<meta property="article:modified_time" content="2021-05-13T09:22:44.007Z">
<meta property="article:author" content="Zlatanlong">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lclong.top/2021/05/13/docker/docker-compose/image-20210513155311383.png">

<link rel="canonical" href="https://lclong.top/2021/05/13/docker/docker-compose/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>使用Docker Compose部署Spring Boot + Mysql项目 | Zlatanlong's T-blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zlatanlong's T-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">Lakers is Championship!</h1>
      
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">38</span></a>

  </li>
        <li class="menu-item menu-item-aboutme">

    <a href="/aboutme/" rel="section"><i class="fa fa-fw fa-user"></i>博主</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lclong.top/2021/05/13/docker/docker-compose/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Zlatanlong">
      <meta itemprop="description" content="生活就像巧克力🍫">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zlatanlong's T-blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          使用Docker Compose部署Spring Boot + Mysql项目
        </h2>

        <div class="post-meta">
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-05-13 17:49:35 / 修改时间：17:22:44" itemprop="dateCreated datePublished" datetime="2021-05-13T17:49:35+08:00">2021-05-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/docker/" itemprop="url" rel="index">
                    <span itemprop="name">docker</span>
                  </a>
                </span>
            </span>

          
            <span id="/2021/05/13/docker/docker-compose/" class="post-meta-item leancloud_visitors" data-flag-title="使用Docker Compose部署Spring Boot + Mysql项目" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">评论次数：</span>
    
    <a title="valine" href="/2021/05/13/docker/docker-compose/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/05/13/docker/docker-compose/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><span class="exturl" data-url="aHR0cHM6Ly9kb2NzLmRvY2tlci5jb20vZ2V0LXN0YXJ0ZWQv" title="https://docs.docker.com/get-started/">Docker官方指引<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3psYXRhbmxvbmcvc3ByaW5nYm9vdC1zdHVkeS90cmVlL21hc3Rlci9zYi0xMC1kb2NrZXI=" title="https://github.com/zlatanlong/springboot-study/tree/master/sb-10-docker">项目Git仓库<i class="fa fa-external-link"></i></span></p>
<h2 id="一、项目基本情况"><a href="#一、项目基本情况" class="headerlink" title="一、项目基本情况"></a>一、项目基本情况</h2><p>Spring Boot项目特别简单，使用Jpa连接数据库，有一个实体类和crud四个rest接口，数据库使用MySQL5.7.34，数据库连接池使用默认的hikari。</p>
<p>docker-compose 需要启动的应用：Spring Boot项目， MySQL</p>
<p>项目结构：</p>
<img src="/2021/05/13/docker/docker-compose/image-20210513155311383.png" alt style="zoom: 80%;">

<p>application.yml:</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="attr">url:</span> <span class="string">$&#123;MYSQL_URL:jdbc:mysql://127.0.0.1:3306/docker_test?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai&#125;</span></span><br><span class="line">    <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">password:</span> <span class="number">123456</span></span><br><span class="line">    <span class="attr">hikari:</span></span><br><span class="line">      <span class="attr">initialization-fail-timeout:</span> <span class="number">10000</span></span><br></pre></td></tr></table></figure>

<p><code>initialization-fail-timeout</code> 这项配置的原因是因为在docker-compose启动时，多线程将任务一起启动，spring boot项目启动会比mysql快，可能造成连接不上数据库而死掉的问题。<code>com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.</code></p>
<h2 id="二、docker-compose-与-Dockerfile-配置"><a href="#二、docker-compose-与-Dockerfile-配置" class="headerlink" title="二、docker-compose 与 Dockerfile 配置"></a>二、docker-compose 与 Dockerfile 配置</h2><a id="more"></a>

<p>docker-compose的配置可以全部写在一个yml中，也可以结合Dockerfile，这里选择结合Dockerfile的写法，参照<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2RvY2tlci9hd2Vzb21lLWNvbXBvc2U=" title="https://github.com/docker/awesome-compose">awesome-compose<i class="fa fa-external-link"></i></span>中的写法。每个独立的内容用自己的Dockerfile来维护，最后使用docker-compose.yml配置结合起来。</p>
<h3 id="Spring-Boot-项目的-Dockerfile："><a href="#Spring-Boot-项目的-Dockerfile：" class="headerlink" title="Spring Boot 项目的 Dockerfile："></a>Spring Boot 项目的 Dockerfile：</h3><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">FROM</span> openjdk:<span class="number">8</span>-alpine</span><br><span class="line"><span class="comment"># Add the service itself</span></span><br><span class="line"><span class="keyword">ARG</span> JAR_FILE</span><br><span class="line"><span class="keyword">ADD</span><span class="bash"> target/<span class="variable">$&#123;JAR_FILE&#125;</span> /usr/share/docker-springboot-demo.jar</span></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">8080</span></span><br><span class="line"><span class="keyword">ENTRYPOINT</span><span class="bash"> [<span class="string">"java"</span>, <span class="string">"-jar"</span>, <span class="string">"/usr/share/docker-springboot-demo.jar"</span>]</span></span><br></pre></td></tr></table></figure>

<p><code>JAR_FILE</code>启动参数在<code>docker-compose.yml</code>中配置。</p>
<h3 id="MySQL项目的Dockerfile"><a href="#MySQL项目的Dockerfile" class="headerlink" title="MySQL项目的Dockerfile:"></a>MySQL项目的Dockerfile:</h3><figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># syntax=docker/dockerfile:1</span></span><br><span class="line"><span class="keyword">FROM</span> mysql:<span class="number">5.7</span>.<span class="number">34</span></span><br><span class="line"><span class="comment">#把sql文件复制到工作目录下</span></span><br><span class="line"><span class="keyword">COPY</span><span class="bash"> ./import.sql /docker-entrypoint-initdb.d</span></span><br></pre></td></tr></table></figure>

<p>这里将MySQL写成一个Dockerfile，是因为要在镜像创建时，就在MySQL中初始本项目需要的表以及数据，初始化脚本在<code>import.sql</code>中。</p>
<blockquote>
<p><span class="exturl" data-url="aHR0cHM6Ly9yZWdpc3RyeS5odWIuZG9ja2VyLmNvbS9fL215c3Fs" title="https://registry.hub.docker.com/_/mysql">MySQL官方镜像中<i class="fa fa-external-link"></i></span>提供了初始化新实例的方法：</p>
<h1 id="Initializing-a-fresh-instance"><a href="#Initializing-a-fresh-instance" class="headerlink" title="Initializing a fresh instance"></a>Initializing a fresh instance</h1><p>When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions <code>.sh</code>, <code>.sql</code> and <code>.sql.gz</code> that are found in <code>/docker-entrypoint-initdb.d</code>. Files will be executed in alphabetical order. You can easily populate your <code>mysql</code> services by <span class="exturl" data-url="aHR0cHM6Ly9kb2NzLmRvY2tlci5jb20vZW5naW5lL3R1dG9yaWFscy9kb2NrZXJ2b2x1bWVzLyNtb3VudC1hLWhvc3QtZmlsZS1hcy1hLWRhdGEtdm9sdW1l" title="https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-file-as-a-data-volume">mounting a SQL dump into that directory<i class="fa fa-external-link"></i></span> and provide <span class="exturl" data-url="aHR0cHM6Ly9kb2NzLmRvY2tlci5jb20vcmVmZXJlbmNlL2J1aWxkZXIv" title="https://docs.docker.com/reference/builder/">custom images<i class="fa fa-external-link"></i></span> with contributed data. SQL files will be imported by default to the database specified by the <code>MYSQL_DATABASE</code> variable.</p>
<p>因此将sql脚本拷贝到容器中或者通过挂载都可以实现。</p>
</blockquote>
<h3 id="docker-compose-yml："><a href="#docker-compose-yml：" class="headerlink" title="docker-compose.yml："></a>docker-compose.yml：</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">"3.8"</span></span><br><span class="line"></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">docker-compose-demo:</span></span><br><span class="line">    <span class="attr">build:</span></span><br><span class="line">      <span class="comment"># dockerfile存放路径</span></span><br><span class="line">      <span class="attr">context:</span> <span class="string">.</span></span><br><span class="line">      <span class="comment"># 配置启动参数</span></span><br><span class="line">      <span class="attr">args:</span></span><br><span class="line">        <span class="attr">JAR_FILE:</span> <span class="string">sb-10-docker-0.0.1-SNAPSHOT.jar</span></span><br><span class="line">      <span class="attr">dockerfile:</span> <span class="string">Dockerfile</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">8890</span><span class="string">:8080</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">     <span class="comment"># 环境变量, 在application.yml中读取</span></span><br><span class="line">      <span class="attr">MYSQL_URL:</span> <span class="string">jdbc:mysql://mysqlserver/docker_test?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">mysqlserver:</span></span><br><span class="line">    <span class="attr">build:</span></span><br><span class="line">      <span class="attr">context:</span> <span class="string">.</span></span><br><span class="line">      <span class="attr">dockerfile:</span> <span class="string">Dockerfile-mysql</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="number">32223</span><span class="string">:3306</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">"sb-10-docker-mysql-data:/var/lib/mysql"</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="attr">MYSQL_ROOT_PASSWORD:</span> <span class="number">123456</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># docker-compose中需要声明named volumes</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">sb-10-docker-mysql-data:</span></span><br></pre></td></tr></table></figure>

<p>在-docker-compose.yml所在文件夹下使用<code>docker-compose up -d</code>，即可启动compose，在docker-desktop中可以看到。</p>
<img src="/2021/05/13/docker/docker-compose/image-20210513162741992.png" alt style="zoom:80%;">

<blockquote>
<p>关于Docker Desktop WSL2 volume 的实际存放位置：/var/lib/docker -&gt; \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes</p>
</blockquote>
<h2 id="三、docker-compose中内外网通信图解"><a href="#三、docker-compose中内外网通信图解" class="headerlink" title="三、docker-compose中内外网通信图解"></a>三、docker-compose中内外网通信图解</h2><p>使用<code>docker inspect containerId</code> 可以查看容器信息，查看其中的网络信息。</p>
<img src="/2021/05/13/docker/docker-compose/image-20210513170908945.png" alt style="zoom:80%;">

<img src="/2021/05/13/docker/docker-compose/未命名绘图.svg" alt style="zoom:80%;">

<p>docker network 的 bridge模式将容器ip映射到宿主机ip，可以通过外部端口进行访问。</p>
<img src="/2021/05/13/docker/docker-compose/image-20210513170501278.png" alt style="zoom:80%;">
    </div>

    
    
    
      

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Zlatanlong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://lclong.top/2021/05/13/docker/docker-compose/" title="使用Docker Compose部署Spring Boot + Mysql项目">https://lclong.top/2021/05/13/docker/docker-compose/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/05/11/%E7%AE%97%E6%B3%95/sort/" rel="prev" title="常用排序算法">
      <i class="fa fa-chevron-left"></i> 常用排序算法
    </a></div>
      <div class="post-nav-item">
    <a href="/9999/02/13/hometop/" rel="next" title="How you doing?">
      How you doing? <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  
  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、项目基本情况"><span class="nav-number">1.</span> <span class="nav-text">一、项目基本情况</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、docker-compose-与-Dockerfile-配置"><span class="nav-number">2.</span> <span class="nav-text">二、docker-compose 与 Dockerfile 配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Spring-Boot-项目的-Dockerfile："><span class="nav-number">2.1.</span> <span class="nav-text">Spring Boot 项目的 Dockerfile：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#MySQL项目的Dockerfile"><span class="nav-number">2.2.</span> <span class="nav-text">MySQL项目的Dockerfile:</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Initializing-a-fresh-instance"><span class="nav-number"></span> <span class="nav-text">Initializing a fresh instance</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-compose-yml："><span class="nav-number">0.1.</span> <span class="nav-text">docker-compose.yml：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、docker-compose中内外网通信图解"><span class="nav-number">1.</span> <span class="nav-text">三、docker-compose中内外网通信图解</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Zlatanlong"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Zlatanlong</p>
  <div class="site-description" itemprop="description">生活就像巧克力🍫</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3psYXRhbmxvbmc=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zlatanlong"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxvbmctdHhnY0Bmb3htYWlsLmNvbQ==" title="E-Mail → mailto:long-txgc@foxmail.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      关注列表
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9sZWZsYWNvbi5naXRodWIuaW8v" title="https:&#x2F;&#x2F;leflacon.github.io&#x2F;">leflacon</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9ib2Jib3NzLmdpdGh1Yi5pby8=" title="https:&#x2F;&#x2F;bobboss.github.io&#x2F;">BobBoss</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cDovL29wdGltaXN0aWNhdC54eXovdXNlcj91c2VySWQ9bHpkY2w=" title="http:&#x2F;&#x2F;optimisticat.xyz&#x2F;user?userId&#x3D;lzdcl">lzdcl</span>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zlatanlong</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">166k</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> v7.7.1
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@latest/canvas-nest-nomobile.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'H5inyassVpcpItLTuMJH9aBg-gzGzoHsz',
      appKey     : 'mBzB6QB3deD6zw8YEIKVQdzz',
      placeholder: "快来说两句吧。。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
